<template>
	<view>
		<view>
			<uni-nav-bar height="40px" style="font-size: 15px; font-weight: bold;" title="ChenPiShop" fixed="true" color="#ff6a00 " shadow="true" class="bar" status-bar="true">
			</uni-nav-bar>
			</view>
		
			
		<uni-search-bar @confirm="search" bg-color="#ffffff" >
			<!-- <uni-popup :show="showDropdown" @hide="hideDropdown">
			      <uni-list>
			        <uni-list-item v-for="option in filteredOptions" :key="option" @click="selectOption()">
			          {{ option }}
			        </uni-list-item>
			      </uni-list>
			    </uni-popup> -->
		</uni-search-bar>
		
		
		
		<swiper circular autoplay :interval="3000" :duration="500" indicator-dots style="height: 450rpx;"
			indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#3CB371">
			<swiper-item v-for="item in banners" :key="item.id">
				<navigator :url="'/pages/detail/detail?businessId=' + item.businessId">
					<image :src="item.img" alt="" mode="scaleToFill" style="width: 100%;" />
				</navigator>
			</swiper-item>
		</swiper>
		
		<!-- 商家分类 -->
		<view class="box" style="margin: 20rpx 0;">
			<view style="display: flex;">
				<view class="category-item" @click="goBusiness('陈皮茶饮')">
				  <image src="@/static/imgs/休闲饮品.png" mode="widthFix" style="width: 50%;"></image>
				  <text>陈皮茶饮</text>
				</view>
				<view class="category-item" @click="goBusiness('陈皮美食')">
					<image src="@/static/imgs/菜菜.png" mode="widthFix" style="width: 50%;"></image>
					<text>陈皮美食</text>
				</view>
				<view class="category-item" @click="goBusiness('陈皮零食')">
					<image src="@/static/imgs/零食.png" mode="widthFix" style="width: 50%;"></image>
					<text>陈皮零食</text>
				</view>
				<view class="category-item" @click="goBusiness('陈皮特产')">
					<image src="@/static/imgs/02_特产.png" mode="widthFix" style="width: 50%;"></image>
					<text>陈皮特产</text>
				</view>
			</view>
		</view>

		<view style="padding: 20rpx;">
			<!-- 公告 -->
			<view class="box">
				<uni-icons type="sound" size="20" style="position: relative; top: 3rpx;"></uni-icons>
				<text style="margin-left: 5rpx;">{{ notice }}</text>
			</view >
				
			<view style="margin-top: 10px;">
				<uni-section title="服务支持" type="line" style="width: 90%;margin-top: 15rpx; color: #ffd281;">
					<view style="padding-bottom: 15rpx; margin-top: 5px;">
						<uni-card title="智能识别" extra="点击前往" @tap="toPage()" sub-title="AI鉴定" thumbnail="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fcfd27216-b3fc-4ecb-b9c5-3ca114e20b11%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1702110876&t=b3fd4a95e777d0f2c85eefe516dfa8be">
							<text class="uni-body">通过训练不同年份和产地的陈皮数据来训练Mobilenet_v2神经网络，来达到精准识别陈皮的年份和产地</text>
						</uni-card>
					</view>
				</uni-section>
			</view>
			   
			<!-- 商家列表 -->
			<view class="box" style="color: orange; font-size: 32rpx; font-weight: bold; margin-bottom: 10rpx;">
				热门商家
			</view>

			<view>
				<view class="box" v-for="item in businessList" :key="item.id"
					style="display: flex; grid-gap: 30rpx; margin-bottom: 10rpx;" @click="goToDeatil(item.id)">
					<view style="width: 30%;">
						<image :src="item.avatar" style="width: 100%; height: 200rpx; border-radius: 10rpx; display: block;"></image>
					</view>
					<view style="flex: 1; display: flex; flex-direction: column; justify-content: space-between; grid-gap: 10rpx;">
						<view style="font-size: 36rpx; font-weight: bold;">{{ item.name }}</view>

						<view style="display: flex;  color: #666; ">
							<view style="flex: 1;">
								<text style="color: #ff9800; font-weight: bold;">{{ item.score }}分</text>
								<text style="margin-left: 10rpx;">已售{{ item.nums }}</text>
							</view>
						</view>
						
						
						<view style="background-color: #ffd281; color: brown; border-radius: 4rpx; width: fit-content;
							padding: 0 8rpx;">{{ item.info || '商家介绍' }}</view>

					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchName:"",
				banners: [],
				noticeList: [],
				notice: '',
				businessList: [],
				
			}
		},
		onLoad() {
			this.load()
		},
		methods: {
			toPage(){
				uni.navigateTo({
					url:'/pages/identify/identify'
				})
				},
			goBusiness(type) {
			  uni.navigateTo({
			    url: '/pages/categoryBusiness/categoryBusiness?type=' + type
			  })
			},
			search(res) {
			  let value = res.value
			  console.log(value);
			  uni.navigateTo({
			    url: '/pages/search/search?name=' + value
			  })
			},
			goToDeatil(businessId) {
			  uni.navigateTo({
			    url: '/pages/detail/detail?businessId=' + businessId
			  })
			},
			load() {
				// 获取轮播图数据
				this.$request.get('/banner/selectAll').then(res => {
					this.banners = res.data || []
				})

				// 获取公告数据
				this.$request.get('/notice/selectAll').then(res => {
					this.noticeList = res.data || []
					if (this.noticeList.length) {
						let i = 0
						this.notice = this.noticeList[i++].content
						if (this.noticeList.length > 1) {
							setInterval(() => {
								if (i === this.noticeList.length) {
									i = 0
								}
								this.notice = this.noticeList[i++].content
							}, 3000)
						}
					}
				})

				// 获取商家的列表
				this.$request.get('/business/selectAll', { status: '通过' }).then(res => {
					this.businessList = res.data || []
				})
				
				
			},
			/* selectOption(){
			  let a=this.search(res)
				console.log(a.value)
				searchName=this.a.value
				this.$request.get('/business/selectAllByGood', { searchName }).then(res => {
					this.filteredOptions = res.data || []
				})
			} */
			
		}
	}
</script>

<style>
	.category-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		grid-gap: 10rpx;
	}
	.bar__title{
		 font-family: 'Microsoft YaHei', sans-serif;
		  font-size: 18px;
		  font-weight: bold;
		  color: #333;
	}

</style>